package com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.task;

import com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.common.SateTraceContext;
import com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.common.SatelliteContext;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author gee
 * @since 2025/5/15 15:40
 */
@Slf4j
public class TmArcStartTask extends AbstractHandler implements TimerTask {

    public TmArcStartTask(List<AbstractHandler> delegateTaskList) {
        super(delegateTaskList);
    }

    private SateTraceContext sateTraceContext;

    @Override
    public void run(Timeout timeout) throws Exception {
        HashedWheelTimer tmFrameTimer = sateTraceContext.getTmFrameTimer();
        SatelliteContext satelliteContext = sateTraceContext.getSatelliteContext();
        Timeout tmFrameTimeout = tmFrameTimer.newTimeout(sateTraceContext.getTmFrameTask(), satelliteContext.getTmSendIntervalMillis(), TimeUnit.MILLISECONDS);
        sateTraceContext.setTmFrameTimeout(tmFrameTimeout);
        log.info("TmArcStartTask  executed");
    }


    @Override
    protected boolean doStart(SateTraceContext sateTraceContext, long simulateTime) {
        log.info("TmArcStartTask doStart");
        this.sateTraceContext = sateTraceContext;
        return true;
    }
}
